package com.yundahh.u8c.service;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.yundahh.u8c.dao.PuInDao;
import com.yundahh.u8c.dao.PuOrderDao;
import com.yundahh.u8c.entity.base.BaseVO;
import com.yundahh.u8c.entity.base.InsertParam;
import com.yundahh.u8c.entity.base.U8CResult;
import com.yundahh.u8c.entity.puin.PuInChild;
import com.yundahh.u8c.entity.puin.PuInParent;
import com.yundahh.u8c.entity.puorder.PuOrderChild;
import com.yundahh.u8c.entity.puorder.PuOrderParam;
import com.yundahh.u8c.entity.puorder.PuOrderParent;
import com.yundahh.u8c.enums.BizType;
import com.yundahh.u8c.enums.OperationType;
import com.yundahh.u8c.exception.U8CApiException;
import com.yundahh.u8c.util.JsonUtils;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;

/**
 * 采购订单业务
 */
public class PuOrderService {

    PuOrderDao puOrderDao=null;

    PuInDao puInDao=null;

    public PuOrderService(PuOrderDao puOrderDao) {
        this.puOrderDao = puOrderDao;
    }

    public PuOrderService(PuOrderDao puOrderDao, PuInDao puInDao) {
        this.puOrderDao = puOrderDao;
        this.puInDao = puInDao;
    }

    public void insert(PuOrderParent puOrderParent, List<PuOrderChild> listChild, boolean needIn){
        try {
            //插入采购订单
            PuOrderParam param=new PuOrderParam();
            BaseVO<PuOrderParent, PuOrderChild> puordervo=new BaseVO<>();
            puordervo.setParentvo(puOrderParent);
            puordervo.setChildrenvo(listChild);
            param.getPuordervo().add(puordervo);
            puOrderDao.send(OperationType.SAVE_APPROVE, JsonUtils.object2Json(param));

            if(needIn){//需要采购入库
//                if(puInDao==null){
//                    throw new U8CApiException("未初始化puInDao");
//                }
//                InsertParam<PuInParent, PuInChild> param=new InsertParam<>();
//                BaseVO<PuInParent, PuInChild> vo=new BaseVO<>();
//
//                //主表数据
//                PuInParent puInParent=new PuInParent();
//                puInParent.setCbiztype(BizType.PU_CP.getCode());
//                puInParent.setEmployee_code("linjian");
//                puInParent.setDispatcher_code("104");//收发类别：成品采购入库
//                puInParent.setDept_code("001010101");//采购部门
//                puInParent.setCoperatorid("15900297774");
//                puInParent.setProvider_code("10");
//                puInParent.setCwarehouseid("05");
//                puInParent.setPk_corp("1003");
//                puInParent.setPk_calbody("1003");
//                //puInParent.setAuditor_code("18500809088");//审核人
//                //puInParent.setPk_defdoc2("");//来源单号
//                puInParent.setPk_defdoc3("linjian");//跟单员
//                puInParent.setPk_defdoc16("02");
//                puInParent.setPk_defdoc17("04");//国内电商
//                vo.setParentvo(puInParent);
//
//                //子表数据
//                PuInChild child1=new PuInChild();
//                child1.setCinventoryid("PUA202206PLA800PCT");
//                child1.setNinnum(new BigDecimal("11"));
//                child1.setBodywarehouse_code("05");
//                child1.setVsourcebillcode("YD-20250910-TC");
//                child1.setVsourcerowno("10");
//                child1.setVfirstbillcode("YD-20250910-TC");
//                child1.setVfirstrowno("10");
//                child1.setCsourcebillhid("1005F71000000005F1MM");
//                child1.setCsourcebillbid("1005F71000000005F1MN");
//
//                child1.setCsourcetype("21");
//
//                vo.getChildrenvo().add(child1);
//
//                param.getGeneralBillVO().add(vo);
//                U8CResult<BaseVO<PuInParent, PuInChild>> send = puInDao.send(OperationType.INSERT, JsonUtils.object2Json(param));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
